home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / ukdate.sty < prev    next >
Text File  |  1995-11-25  |  10KB  |  204 lines

  1. % --- ------------------------------------------------------------------
  2. % ---       English-style Date Macros for LaTeX, version 1.00--0.
  3. % --- ------------------------------------------------------------------
  4. %
  5. % --- \today (replaces American-style macro of same name)  generates
  6. % ---        today's date in the form Thursday 4th October 1066.
  7. % ---        The `th' is raised, reduced in size and underlined in the
  8. % ---        same font style (family) as the rest of the date.
  9. %
  10. % --- \st    generates a raised, reduced, underlined `st', as in 1st.
  11. % --- \nd    generates a raised, reduced, underlined `nd', as in 2nd.
  12. % --- \rd    generates a raised, reduced, underlined `rd', as in 3rd.
  13. % --- \th    generates a raised, reduced, underlined `th', as in 4th.
  14. %
  15. % --- \dayofweek  generates the day of the week, based on TeX's values
  16. % ---        of \day, \month and \year.
  17. %
  18. % --- \phaseofmoon generates the current phase of the moon, again based
  19. % ---        on TeX's values for \day, \month and \year.
  20. %
  21. % --- ------------------------------------------------------------------
  22. % ---     Adrian F. Clark  (alien@uk.ac.essex.ese)  26-Oct-1988 10:05:50
  23. % --- ------------------------------------------------------------------
  24.  
  25. % --- Counters.  Note that we use the same registers as TeX holds other
  26. % --- things in (e.g., \count0 holds the page number).  This requires
  27. % --- that \@savestyle, \@setstyle, \dayofweek and \phaseofmoon perform
  28. % --- all their register manipulations within a group.  This may seem
  29. % --- a bit messy, but it saves having eight registers permanently set
  30. % --- aside just for date calculation.
  31.  
  32. \def\@cent{\count0 }                       % century number (1979 == 20)
  33. \def\@diy{\count1 }                        % day in the year
  34. \def\@dow{\count2 }                        % gets day of the week
  35. \def\@epact{\count3 }                      % age of the moon on Jan. 1
  36. \def\@golden{\count4 }                     % Moon's golden number
  37. \def\@leap{\count5 }                       % leap year fingaler
  38. \def\@x{\count6 }                          % temp register
  39. \def\@y{\count7 }                          % another temp register
  40.  
  41.  
  42. % --- A replacement for the ``plain'' TeX and LaTeX \today macro, to
  43. % --- to output the date in English-style.
  44. % --- They ensure the smaller text comes out in the right font by saving
  45. % --- the font family before reducing the size, then restoring it.  (This
  46. % --- was suggested by Leslie Lamport.)  Of course, it requires that the
  47. % --- font in use when today is invoked has a sensible family.
  48.  
  49. \def\@up#1{{\@savestyle\thinspace$^{\underline{\hbox{%
  50.   \scriptsize\@setstyle#1\fam=-1 }}}$}}
  51. \def\st{\@up{st}}
  52. \def\nd{\@up{nd}}
  53. \def\rd{\@up{rd}}
  54. \def\th{\@up{th}}
  55.  
  56. % --- Macros to save and restore the font family.
  57.  
  58. \def\@savestyle{\count0=\the\fam}
  59. \def\@setstyle{\ifcase\count0\rm\or\mit\or\cal\or\rm% what's family 3?
  60.   \or\it\or\sl\or\bf\or\tt\fi}
  61.  
  62. % --- The date, English style (e.g. Thursday 4th October 1066).
  63.  
  64. \def\today{\dayofweek\ \number\day\ifcase\day
  65.   \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  66.   \or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\th
  67.   \or\st\or\nd\or\rd\or\th\or\th\or\th\or\th\or\th\or\th\or\th\or\st\fi
  68.   \space\ifcase\month\or January\or February\or March\or April\or May\or
  69.   June\or July\or August\or September\or October\or November\or December\fi
  70.   \space\number\year}
  71.  
  72. % --- The day of the week ("Sunday", etc.) is inserted into the text
  73. % --- by \dayofweek. (This uses registers \@dow, \@leap, \@x and \@y.)
  74. % --- I acquired this from elsewhere; I don't know who wrote it.
  75.  
  76. \def\dayofweek{{%
  77. %            leap = year + (month - 14)/12;
  78.   \@leap=\month \advance\@leap by -14 \divide\@leap by 12
  79.   \advance\@leap by \year
  80. %            dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  81.   \@dow=\month \advance\@dow by 10
  82.   \@y=\@dow \divide\@y by 13 \multiply\@y by 12
  83.   \advance\@dow by -\@y \multiply\@dow by 13 
  84.   \advance\@dow by -1 \divide\@dow by 5
  85. %            dow += day + 77 + 5 * (leap % 100)/4
  86.   \advance\@dow by \day \advance\@dow by 77
  87.   \@x=\@leap \@y=\@x \divide\@y by 100 \multiply\@y by 100 \advance\@x by -\@y
  88.   \multiply\@x by 5 \divide\@x by 4 \advance\@dow by \@x
  89. %            dow += leap / 400
  90.   \@x=\@leap \divide\@x by 400 \advance\@dow by \@x
  91. %            dow -= leap / 100 * 2;
  92. %            dow = (dow % 7)
  93.   \@x=\@leap \divide\@x by 100 \multiply\@x by 2 \advance\@dow by -\@x
  94.   \@x=\@dow \divide\@x by 7 \multiply\@x by 7 \advance\@dow by -\@x
  95.   \ifcase\@dow Sunday\or Monday\or Tuesday\or Wednesday\or
  96.       Thursday\or Friday\or Saturday\fi}}
  97. %
  98. % --- Likewise, \phaseofmoon inserts the phase of the moon into the
  99. % --- text. This was written by the same person as \dayofweek.
  100. % --- The routine calculates the year's epact (the age of the moon on Jan 1.),
  101. % --- adds this to the number of days in the year, and calculates the phase
  102. % --- of the moon for this date.  It returns the phase as a string, e.g.,
  103. % --- "new", "full", etc.
  104. %
  105. % --- In the algorithm:
  106. % ---      diy       is the day of the year - 1 (i.e., Jan 1 is day 0).
  107. % ---      golden    is the number of the year in the Mentonic cycle, used to
  108. % ---                determine the position of the calender moon.
  109. % ---      epact     is the age of the calender moon (in days) at the beginning
  110. % ---                of the year.  To calculate epact, two century-based
  111. % ---                corrections are applied:
  112. % ---                Gregorian:      (3 * cent)/4 - 12
  113. % ---                      is the number of years such as 1700, 1800 when
  114. % ---                      leap year was not held.
  115. % ---                Clavian:      (((8 * cent) + 5) / 25) - 5
  116. % ---                      is a correction to the Mentonic cycle of about
  117. % ---                      8 days every 2500 years.  Note that this will
  118. % ---                      overflow 16 bits in the year 409600.  Beware.
  119. % --- The algorithm is accurate for the Gregorian calender only.
  120. %
  121. % --- The magic numbers used in the phase calculation are:
  122. % ---      29.5            The moon's period in days.
  123. % ---     177              29.5 scaled by 6
  124. % ---      22              (29.5 / 8) scaled by 6 (this gets the phase)
  125. % ---      11              ((29.5 / 8) / 2) scaled by 6
  126. %
  127. % --- Theoretically, this should yield a number in the range 0 .. 7.  However,
  128. % --- two days per year, things don't work out too well.
  129. %
  130. % --- Epact is calculated by the algorithm given in Knuth vol. 1 (Calculation
  131. % --- of Easter).  See also the article on Calenders in the Encyclopaedia
  132. % --- Britannica and Knuth's algorithm in CACM April 1962, page 209.
  133. %
  134. \def\phaseofmoon{{%
  135.   \@diy=\day \advance\@diy by \ifcase\month            % Jan 1 == 0
  136.       -1\or -1\or 30\or 58\or 89\or 119\or 150\or      % Jan .. Jun
  137.       180\or 211\or 241\or 272\or 303\or 333\fi        % Jul .. Dec
  138. %            if ((month > 2) && ((year % 4 == 0) &&
  139. %                ((year % 400 == 0) || (year % 100 != 0))))
  140. %                  diy++;            /* Leapyear fixup      */
  141.   \ifnum \month>2
  142.     \@x=\year \@y=\@x \divide\@y by 4 \multiply\@y by 4 \advance\@x by -\@y
  143.     \ifnum \@x=0                    % month > 2 and maybe leapyear
  144.       \@x=\year \@y=\@x \divide\@y by 400 
  145.       \multiply\@y by 400 \advance\@x by -\@y
  146.       \ifnum \@x=0                  % 2000 is a leap year
  147.       \advance\@diy by 1            % so it's one day later
  148.       \else                         % not 2000, check other '00's
  149.       \@x=\year \@y=\@x \divide\@y by 100 
  150.       \multiply\@y by 100 \advance\@x by -\@y
  151.       \ifnum \@x>0                  % not some other '00' year
  152.           \advance\@diy by 1        % it's still one day later
  153.       \fi                           % not odd century
  154.       \fi                           % not 2000-type century
  155.     \fi                             % not leapish year
  156.   \fi                               % not march or later
  157. %            cent = (year / 100) + 1;      /* Century number */
  158. %            golden = (year % 19) + 1;      /* Golden number */
  159.   \@cent=\year \divide\@cent by 100 \advance\@cent by 1
  160.   \@golden=\year
  161.   \@y=\year \divide\@y by 19 \multiply\@y by 19 \advance\@golden by -\@y
  162.   \advance\@golden by 1
  163. %            epact = ((11 * golden) + 20        /* Golden number */
  164. %            + (((8 * cent) + 5) / 25) - 5      /* 400 year cycle */
  165. %            - (((3 * cent) / 4) - 12)) % 30;   /* Leap year correction */
  166.   \@epact=11 \multiply\@epact by \@golden
  167.   \advance\@epact by 20
  168.   \@x=8 \multiply\@x by \@cent \advance\@x by 5
  169.   \divide\@x by 25 \advance\@x by -5
  170.   \advance\@epact by \@x
  171.   \@x=3 \multiply\@x by \@cent \divide\@x by 4 \advance\@x by -12
  172.   \advance\@epact by -\@x
  173.   \@y=\@epact \divide\@y by 30 \multiply\@y by 30 \advance\@epact by -\@y
  174. %      if (epact <= 0)
  175. %            epact += 30;                  /* Age range is 1 .. 30 */
  176. %      if ((epact == 25 && golden > 11) || epact == 24)
  177. %            epact++;
  178.   \ifnum \@epact<0
  179.     \advance\@epact by 30
  180.   \fi
  181.   \ifnum \@epact=25
  182.     \ifnum \@golden>11
  183.       \advance \@epact by 1
  184.     \fi
  185.   \else
  186.     \ifnum \@epact=24
  187.       \advance \@epact by 1
  188.     \fi
  189.   \fi
  190. %
  191. % --- Calculate the phase, using the magic numbers defined above.
  192. % --- Note that phase may be equal to 8 (== 0) on two days of the year
  193. % --- due to the way the algorithm was implemented.
  194. % ---      phase = (((((diy + epact) * 6) + 11) % 177) / 22) & 7;
  195. %
  196.   \@x=\@diy \advance\@x by \@epact \multiply\@x by 6 \advance\@x by 11
  197.   \@y=\@x \divide\@y by 177 \multiply\@y by 177 \advance\@x by -\@y
  198.   \divide\@x by 22
  199.   \ifcase\@x new\or waxing crescent\or in its first quarter\or
  200.       waxing gibbous\or full\or waning gibbous\or
  201.       in its last quarter\or waning crescent\or new\fi}}
  202.  
  203. % --- End of ukdate.sty
  204.